<template>
    <div class="page">
        <el-card shadow="never">
            <div class="name mb-6">{{ form.name }}</div>
            <div class="desc">角色地图账号：{{ form.information }}</div>
            <div class="desc">角色地图账号注册时间：{{ form.register_at | formatTime('YYYY/MM/DD') }}</div>
            <div class="desc">最后一次访问角色地图时间：{{ form.last_login_at | formatTime('YYYY/MM/DD') }}</div>

            <el-collapse class="mt-10" v-model="activeNames">
                <el-collapse-item v-for="(item, i) in list" :key="i" :name="i">
                    <template slot="title">
                        <div class="medal-course">
                            <div class="medal-course-top">开通勋章课名称</div>
                            <div class="medal-course-title">{{ item.name }}</div>
                        </div>
                    </template>
                    <div class="medal-course">
                        <div class="medal-course-top">学过的小节</div>
                        <el-table :data="item.learnList">
                            <el-table-column align="center" type="index" label="序号"/>
                            <el-table-column align="center" label="名称" prop="name"/>
                        </el-table>
                    </div>
                    <div class="medal-course">
                        <div class="medal-course-top">点击学完的小节</div>
                        <el-table :data="item.completeList">
                            <el-table-column align="center" type="index" label="序号"/>
                            <el-table-column align="center" label="名称" prop="name"/>
                        </el-table>
                    </div>
                    <div class="medal-course">
                        <div class="medal-course-top">首次学习时间</div>
                        <div>{{ item.first_learn_at | formatTime('YYYY/MM/DD') }}</div>
                    </div>
                    <div class="medal-course">
                        <div class="medal-course-top">最后学习时间</div>
                        <div>{{ item.last_learn_at | formatTime('YYYY/MM/DD') }}</div>
                    </div>
                </el-collapse-item>
            </el-collapse>
            <div class="flex justify-center mt-4">
                <el-pagination
                    class="center"
                    @current-change="setData"
                    :current-page.sync="pagination.page"
                    :page-size="pagination.size"
                    :total="total">
                </el-pagination>
            </div>
            <div class="text-center mt-4">
                <el-button @click="onBack">返 回</el-button>
            </div>
        </el-card>
    </div>
</template>

<script>
import { Collapse, CollapseItem } from 'element-ui';

export default {
    components: {
        ElCollapse: Collapse,
        ElCollapseItem: CollapseItem,
    },
    data() {
        return {
            form: {
                content: '',
                name: '',
            },
            activeNames: [],

            pagination: {
                page: 1,
                size: 5,
            },
            list: [],
            total: 0,
        };
    },
    methods: {

        getDetail() {
            this.loading = true;
            API.get(`user/merit-course-statistics/${this.id}`).then(res => {
                let courseList = res.merit_course_statistics_responses || [];
                courseList = courseList.map((item, i) => {
                    const response = item.response || [];
                    const completeList = [];
                    for (const jItem of response) {
                        if (jItem.is_complete) completeList.push(jItem);
                    }
                    item.learnList = response;
                    item.completeList = completeList;
                    this.activeNames.push(i);
                    return item;
                });
                this.list = courseList.slice(0, this.pagination.size);
                this.total = courseList.length;
                this.form = {...res, ...{merit_course_statistics_responses: courseList}};
            }).finally(() => this.loading = false);
        },

        setData(e) {
            const dataList = this.form.merit_course_statistics_responses || [];
            const index = (e - 1) * this.pagination.size;
            this.list = dataList.slice(index, index + this.pagination.size);
        },

        onBack() {
            this.$router.back();
        },
    },
    mounted() {
        this.id = this.$route.params.id;
        if (this.id) this.getDetail();
    },
};
</script>

<style lang="scss" scoped>
.name {
    font-size: 24px;
    color: #3c3c3c;
}

.desc {
    font-size: 16px;
    color: #818181;
    margin-bottom: 10px;
}

::v-deep {
    .el-collapse-item__header {
        height: 100px;
        line-height: 1;
    }

    .el-collapse-item__content {
        .medal-course {
            margin-top: 30px;
        }
    }

    .el-collapse-item__wrap {
        border-bottom-width: 0;
    }

    .el-collapse-item__content {
        padding-bottom: 120px;
    }
}

.medal-course {
    line-height: normal;

    .medal-course-top {
        font-size: 18px;
        color: rgb(18, 157, 238);
        margin-bottom: 8px;
    }

    .medal-course-title {
        font-size: 20px;
        text-decoration: underline;
        color: #818181;
        font-weight: 400;
    }
}

.medal-ul {
    li {
        list-style: inside;
    }
}
</style>
